package com.jl.commons.utils;

import java.util.*;

/**
 * 数学方法工具类
 */
public class MathMethodUtil {

    public static void main(String[] args) {

        Random random = new Random();

        String[] json = new String[]{"[{\"faultPartId\": 1,\"falutPartName\": \"机械部位\",\"changeComponent\": []}]",
                "[{\"faultPartId\": 3,\"falutPartName\": \"液压部位\",\"changeComponent\": []}]",
                "[{\"faultPartId\": 2,\"falutPartName\": \"电气部位\",\"changeComponent\": []}]",
                "[{\"faultPartId\": 4,\"falutPartName\": \"气压部位\",\"changeComponent\": []}]"};


        for (int i = 1; i <= 3860; i++) {
            int number1 = random.nextInt(4);
            System.out.println(json[number1]);
        }


    }

    public static void getsd() {
        List<Integer> integerList = new ArrayList<>();
        Random random = new Random();
        int i = 0;
        while (i < 3) {
            int number1 = random.nextInt(10) + 1;
            if (integerList.contains(number1)) {
                continue;
            } else {
                integerList.add(number1);
                i++;
            }
        }
        System.out.println(integerList.get(0) + "," + integerList.get(1) + "," + integerList.get(2));
    }


    /**
     * 获得中位数
     *
     * @param data 数据数据集合（Integer）
     * @return 中位数
     */
    public static Integer getMedian(List<Integer> data) {
        Integer mid = 0;
        Collections.sort(data);
        Integer len = data.size();
        if(data.isEmpty()){
            return 0;
        }else{
            if(len.equals(1)){
                return data.get(0);
            }
            Integer minIndex = len / 2;
            if (len % 2 == 0) {
                mid = (data.get(minIndex) + data.get(minIndex - 1)) / 2;
            } else {
                mid = data.get(minIndex);
            }
        }
        return mid;
    }

    /**
     * 获得众位数
     *
     * @param data 数据数据集合（Integer）
     * @return 众数
     */

    public static Integer getModeNumber(List<Integer> data) {
        HashSet<Integer> uniqueData = new HashSet<Integer>(data);
        HashMap<Integer, Integer> mass = new HashMap<Integer, Integer>();
        int[] count = new int[uniqueData.size()];
        int j = 0;
        for (Integer integer1 : uniqueData) {
            for (Integer integer2 : data) {
                if (integer1.equals(integer2)) count[j]++;
            }
            mass.put(count[j], integer1);
            j++;
        }
        int k = 0;
        for (int i : count) {
            k = Math.max(k, i);
        }
        System.out.println("数组data的众数为：" + mass.get(k));
        return mass.get(k);
    }

}
